﻿

using System;

namespace PECommon {

    /// <summary>
    /// 计时任务抽象基类
    /// </summary>
    public abstract class PETimer {
        public Action<string> LogFunc;
        public Action<string> WarnFunc;
        public Action<string> ErrorFunc;

        /// <summary>
        /// 创建定时任务
        /// </summary>
        /// <param name="delay">定时任务时间</param>
        /// <param name="taskCB">定时任务回调</param>
        /// <param name="cancelCB">取消任务回调</param>
        /// <param name="count">任务重复次数</param>
        /// <returns>当前计时器唯一任务ID</returns>
        public abstract int AddTask(
            uint delay,
            Action<int> taskCB,
            Action<int> cancelCB,
            int count = 1);
        /// <summary>
        /// 删除定时任务
        /// </summary>
        /// <param name="tid">定时任务ID</param>
        /// <returns>删除操作结果</returns>
        public abstract bool DeleteTask(int tid);
        /// <summary>
        /// 重置计时器
        /// </summary>
        public abstract void Reset();

        protected int tid = 0;
        /// <summary>
        /// 生成定时任务唯一ID号
        /// </summary>
        protected abstract int GenerateTid();
    }
}